<form class="layui-form layui-form-pane" method="post" action="" enctype="multipart/form-data" >
    <style>
        #demo2 img {
            width: 100px;
            margin-left: 20px;
        }
    </style>
    @csrf
    {{--<div class="layui-form-item">--}}
        {{--<label class="layui-form-label">类型</label>--}}
        {{--<div class="layui-input-inline" style="width:50%;">--}}
            {{--<input type="radio" name="type" value="1"  lay-filter="type" title="图文" checked>--}}
            {{--<input type="radio" name="type" value="2"  lay-filter="type" title="视频">--}}
            {{--<input type="radio" name="type" value="3"  lay-filter="type" title="问答">--}}
        {{--</div>--}}
        {{--<div class="layui-form-mid layui-word-aux"></div>--}}
    {{--</div>--}}
    <input type="hidden" name="id" value="{{$id}}">
    <input type="hidden" name="type" value="2">
    <div class="layui-form-item" id="title">
        <label class="layui-form-label">标题</label>
        <div class="layui-input-inline" style="width:30%;">
            <input type="type" name="titles" value='' placeholder='请输入标题' autocomplete="off" class="layui-input" >
        </div>
        <div class="layui-form-mid layui-word-aux"></div>
    </div>
    <div class="layui-form-item" id="qrcode">
        <label class="layui-form-label">封面图</label>
        <button type="button" class="layui-btn" id="test3"><i class="layui-icon"></i>上传文件</button>
        <input type="hidden" name="picname" id="picname">
    </div>

    <div class="layui-form-item" id="video">
        <label class="layui-form-label">视频:</label>
        <button type="button" class="layui-btn" id="test5"><i class="layui-icon"></i>上传视频</button>
        <input type="hidden" name="vedio" id="vedio_c">
    </div>
    <div class="layui-form-item" >
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
    <input type="hidden" name="page" value="{{$request->page}}">
    <input type="hidden" name="keywords" value="{{$request->keywords}}">
    <input type="hidden" name="label" value="{{$request->label}}">
    <input type="hidden" name="types" value="{{$request->type}}">
    <input type="hidden" name="brand" value="{{$request->brand}}">
    <input type="hidden" name="state" value="{{$request->state}}">
    <input type="hidden" name="sell" value="{{$request->sell}}">
    <input type="hidden" name="month" value="{{$request->month}}">
    <input type="hidden" name="title" value="{{$request->title}}">
    <input type="hidden" name="sort" value="{{$request->sort}}">
</form>
<script>
    //Demo
    layui.use('form', function(){
        var form = layui.form;
        form.render();

        layui.use('upload',function(){
            var $ = layui.jquery
                ,upload = layui.upload;
            //指定允许上传的文件类型
            upload.render({
                elem: '#test3'
                ,url: '/admin/source_up' //改成您自己的上传接口
                ,accept: 'file' //普通文件
                ,done: function(res){
                    layer.msg(res.msg);
                    if(res.code == 1){
                        $("#test3").text('上传成功!');
                        $("#picname").val(res.info);
                    }
                }
            });
            upload.render({
                elem: '#test5'
                ,url: '/admin/source_ve' //改成您自己的上传接口
                ,accept: 'video' //视频
                ,done: function(res){
                    if(res['code'] == 1){
                        $("#test5").text('上传成功!'+res['data_cy']);
                        $("#vedio_c").val(res['data']);
                    }
                    layer.msg('上传成功');
                    console.log(res)
                }
            });

            //多图片上传
            upload.render({
                elem: '#test2'
                , url: '/admin/source_up' //改成您自己的上传接口
                , multiple: true
                , before: function (obj) {
                    //预读本地文件示例，不支持ie8
                    obj.preview(function (index, file, result) {
                        $('#demo2').append('<img src="' + result + '" alt="' + file.name + '" class="layui-upload-img">')
                    });
                }
                , done: function (res) {
                    layer.msg(res.msg);
                    //上传完毕
                    if (res.code == 1) {
                        $("#test3").text('上传成功!' + res.data);
                        var picname = $("#pics").val();
                        $("#pics").val(picname + res.info + ',');
                    }
                }
            });
        });

        layui.use(['layedit','form'],
            function() {
                var layedit = layui.layedit;
                var index = layedit.build('demo'); //建立编辑器
                var form = layui.form;
                var layedit = layui.layedit;

                //监听提交
                form.on('submit(formDemo)', function(data){
                    var aa = layedit.getContent(index);
                    var page = $("input[name=page]").val();
                    var keywords = $("input[name=keywords]").val();
                    var label = $("input[name=label]").val();
                    var types = $("input[name=types]").val();
                    var brand = $("input[name=brand]").val();
                    var state = $("input[name=state]").val();
                    var sell = $("input[name=sell]").val();
                    var month = $("input[name=month]").val();
                    var title = $("input[name=title]").val();
                    var sort = $("input[name=sort]").val();
                    data.field.contents = aa;
                    layer.confirm('确认执行此操作？', {icon: 3, title:'提示'}, function(index){
                        ajax("{{url('admin/shop/source_insert')}}",data.field,function(data){
                            layer.close();
                            layer.closeAll();
                            layer.msg(data.msg);
                            if(data.code == 1){
                                location.href=location.href;
                                {{--location.href = '/admin/shop/source?id='+ {{$id}}+'&types='+data['data']+'&page='+page+'&keywords='+keywords+'&label='+label+'&type='+types+'&brand='+brand+'&state='+state+'&sell='+sell+'&month='+month+'&title='+title+'&sort='+sort;--}}
                            }
                        });
                    });
                    return false;
                });
            });

        });
</script>
